package com.lihui;

import java.lang.reflect.Array;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/09/23  19:30
 */
class MyArray04<T> {
    // 这里先暂且这样写
    private T[] arrays;

    public MyArray04 (Class<T> clazz, int capacity) {
        this.arrays = (T[]) Array.newInstance(clazz, capacity);
    }

    // 这里先不做非空，越界等校验，只做演示
    public void setValue (int pos, T value) {
        arrays[pos] = value;
    }

    public T getPos (int pos) {
        return arrays[pos];
    }

    public T[] getArrays () {
        return arrays;
    }
}
public class Demo04 {
    public static void main(String[] args) {
        MyArray04<Integer> myArray04 = new MyArray04<>(Integer.class, 10);
        myArray04.setValue(0, 10);
        Integer[] temp = myArray04.getArrays();
        System.out.println(temp[0]);

        MyArray04<String> myArray041 = new MyArray04<>(String.class, 10);
        myArray041.setValue(0, "hello");
        String[] temp1 = myArray041.getArrays();
        System.out.println(temp1[0]);

    }
}

